<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xml:space="default">
  <xsl:output method="xml" encoding="windows-1250" indent="yes"/>
  
  <xsl:template match="/">
    <Concepts>
      <xsl:apply-templates select="/node()/Concepts[1]/Concept" mode="regular"/>
      <xsl:apply-templates select="/node()/Concepts[2]/Concept" mode="fw"/>
    </Concepts> 
  </xsl:template>
  
  <xsl:template match="Concept" mode="regular">
    <xsl:copy>
      <xsl:variable name="iscoverer" select="not(../Concept/CAssociations/CAssociation[@type='composite' and @id_cchild=current()/@id_concept])"/>
      <xsl:if test="$iscoverer">
        <xsl:attribute name="iscovereroot">yes</xsl:attribute>      
      </xsl:if>    

      <xsl:if test="not(../Concept/CAssociations/CAssociation[@type='composite' and @id_cchild=current()/@id_concept])">
        <xsl:attribute name="iscovereroot">yes</xsl:attribute>      
      </xsl:if>    
      <xsl:if test="../Concept/CAssociations/CAssociation[@type='recursive' and @id_cchild=current()/@id_concept]">
        <xsl:attribute name="xxxrecursive">yes</xsl:attribute>   
      </xsl:if>          
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="*"/>      

      <xsl:if test="$iscoverer and @name!='OAttachment'">
        <CAssociations>
          <!-- Add framework association to OAttachment -->
          <CAssociation cardinality="1:n" id_cassociation="50" id_cchild="9a816913-1308-11db-ae19-fbf090d0671a" id_cparent="{@id_concept}" inhassoc="0" inhassocmember="0" linkname="oattachments" position="1000020" type="composite">
            <CABindings>
              <CABinding id_cassociation="50" id_cchild="9a816913-1308-11db-ae19-fbf090d0671a" id_cparent="{@id_concept}" p1="{CProperties/CProperty[@key='1']/@name}" p2="ID_Object" position="100.0"/>
            </CABindings>
          </CAssociation>
        </CAssociations>
      </xsl:if>    

    </xsl:copy>
  </xsl:template>

  <xsl:template match="Concept" mode="fw">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="*"/>      
    </xsl:copy>
  </xsl:template>

      
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
    
</xsl:stylesheet>